﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using Model;
using Model.WWW_WWW.files;

namespace WebServices.WWW
{
    /// <summary>
    /// Files 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://www.italki.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class Files : System.Web.Services.WebService
    {
        /// <summary>
        /// 添加评论
        /// （0：CommonMessage.msg.Msg = "l"未登录、"n"内容为空、"s"执行失败，State="true"执行成功
        /// 1：评论列表(分页)DocCommentModel List，2：评论记录，3：分页信息）
        /// </summary>
        /// <param name="docid">文档ID</param>
        /// <param name="desc">评论内容</param>        
        /// <param name="pageSize">页数据条数</param>
        /// <param name="pageIndex">pageIndex</param>        
        /// <returns>ArrayList</returns>
        [WebMethod]
        public ArrayList AddComment(string docid, string desc, int pageSize, int pageIndex)
        {
            ArrayList outList = new ArrayList();
            CommonMessage msg = new CommonMessage();
            if (HttpContext.Current.User.Identity.Name == "")
            {
                msg.Msg = "l";
                outList.Add(msg);
                return outList;
            }
            if (string.IsNullOrEmpty(desc) || desc.Trim() == "")
            {
                msg.Msg = "n";
                outList.Add(msg);
                return outList;
            }
            msg = BLF.WWW_WWW.Files.Files.AddCommentOfPage(docid, desc, pageSize, pageIndex, out outList);
            if (!msg.State) msg.Msg = "s";

            int k = (int)outList[1];
            outList.RemoveAt(1);
            outList.Insert(1, new BLF.PageableObject(k, 1, pageSize));

            outList.Insert(2, msg);
            outList.Insert(3,k);
            return outList;
        }
        /// <summary>
        /// 添加评论
        /// （0：CommonMessage.msg.Msg = "l"未登录、"n"内容为空、"s"执行失败，State="true"执行成功
        /// 1：评论列表DocCommentModel List，2：评论记录）
        /// </summary>
        /// <param name="docid">文档ID</param>
        /// <param name="desc">评论内容</param>        
        /// <param name="pageSize">页数据条数</param>             
        /// <returns>ArrayList</returns>
        [WebMethod]
        public ArrayList AddComment1(string docid, string desc,int pageSize)
        {
            ArrayList outList = new ArrayList();
            CommonMessage msg = new CommonMessage();
            if (HttpContext.Current.User.Identity.Name == "")
            {
                msg.Msg = "l";
                outList.Add(msg);
                return outList;
            }
            if (string.IsNullOrEmpty(desc) || desc.Trim() == "")
            {
                msg.Msg = "n";
                outList.Add(msg);
                return outList;
            }
            msg = BLF.WWW_WWW.Files.Files.AddCommentNoPage(docid, desc, pageSize, out outList);
            if (!msg.State) msg.Msg = "s";
            outList.Insert(0, msg);
            return outList;
        }
        /// <summary>
        /// 添加一个用户喜欢的文档记录
        /// </summary>
        /// <param name="docId">文件ID</param>
        [WebMethod]
        public CommonMessage AddLike(string docid)
        {
            CommonMessage msg = new CommonMessage();
            if (HttpContext.Current.User.Identity.Name == "")
            {
                msg.Msg = "l";
                return msg;
            }
            msg = BLF.WWW_WWW.Files.Files.AddLike(docid, HttpContext.Current.User.Identity.Name);            
            return msg;
        }
        /// <summary>
        /// 删除用户喜欢的文档记录
        /// </summary>
        /// <param name="docId">文件ID</param>       
        /// <returns>CommonMessage</returns>
        [WebMethod]
        public CommonMessage DeleteLike(string docId)
        {
            CommonMessage msg = new CommonMessage();
            if (HttpContext.Current.User.Identity.Name == "")
            {
                msg.Msg = "l";
                return msg;
            }
            msg = BLF.WWW_WWW.Files.Files.DeleteLike(docId, HttpContext.Current.User.Identity.Name);
            return msg;
        }

        [WebMethod]
        public ArrayList Rate(string pageName, int v)
        {
            ArrayList outList = new ArrayList();
            CommonMessage msg = new CommonMessage();
            if (v < 1 || v > 5)
            {
                outList.Add(msg);
                return outList;
            }
            msg = BLF.WWW_WWW.Files.Files.Rate(pageName, Guid.NewGuid().ToString("N"), HttpContext.Current.Request.UserHostAddress, HttpContext.Current.User.Identity.Name, v, out outList);
            outList.Insert(0, msg);
            return outList;
        }
    }
}
